/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package anjos.dao;

import anjos.modelo.AnjoEvento;
import anjos.modelo.AnjoEventoPK;
import anjos.modelo.Evento;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;

/**
 *
 * @author AlanmLira
 */
public class AnjoEventoDAO {

    GenericDAO<AnjoEvento> dao = new GenericDAO<>();
    private EntityManager em = FabricaEntityManager.obterFactory().createEntityManager();//obterFabrica().createEntityManager();

    public AnjoEvento obterAnjo(Class<AnjoEvento> classe, String senha, Evento evento) {
        String query = classe.getSimpleName() + ".findByEventoSenha";
        final Query q = em.createNamedQuery(query);
        q.setParameter("eventoID", evento.getId());
        q.setParameter("senha", senha);
        return (AnjoEvento) q.getSingleResult();
    }

    public AnjoEvento findAnjoEventoBySenhaId(Evento eve, String senha) {
        List list = dao.findByQueries("select o from AnjoEvento o where o.evento.id="+eve.getId()+" and o.senha ='"+senha+"'", 0, 0);
        AnjoEvento anjoEvento = null;

        if (!list.isEmpty()) {
            anjoEvento = (AnjoEvento) list.get(0);
        }

        return anjoEvento;
    }
}
